package com.tzy.newbank;

import com.tzy.newbank.BankDao.MyBankTestDao;
import com.tzy.newbank.Pojo.Bankuser2;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Optional;

@SpringBootTest
public class SpringDataTest2 {

    @Autowired
    private MyBankTestDao myBankTestDao;

    //根据id查询
    @Test
    public void test(){
        System.out.println(myBankTestDao.findByUserid(4));
    }

    @Test
    public void test1() {
        Optional<Bankuser2> result = myBankTestDao.findById(4);
        result.ifPresent(System.out::println);  // 使用Optional避免空指针异常
    }

    // 测试根据userid查找数据
    @Test
    public void testFindByUserid() {
        Bankuser2 result = myBankTestDao.findByUserid(4);
        if (result != null) {
            System.out.println(result);
        } else {
            System.out.println("No user found with id 4");
        }
    }

    // 测试根据name查找数据
    @Test
    public void testFindByName() {
        Bankuser2 result = myBankTestDao.findBankuser2BySql("tt");
        if (result != null) {
            System.out.println(result);
        } else {
            System.out.println("No user found with name 'Tom'");
        }
    }
}
